<!-- 订单管理 -->
<template>
  <el-form ref="ruleFormRef" :model="ruleForm" inline class="ruleForm">
    <el-form-item label="订单号：" prop="orderNo">
      <el-input
        v-model="ruleForm.queryRo.orderNo"
        style="width: 150px"
        clearable
        placeholder="请输入订单号"
      />
    </el-form-item>
    <el-form-item label="充电开始-结束时间：" >
      <el-date-picker
        v-model="time"
        type="datetimerange"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始时间"
        end-placeholder="结束时间"
        value-format="YYYY-MM-DD HH:mm:ss"
        align="right">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="下单时间：" >
      <el-date-picker
          v-model="createtime"
          type="datetimerange"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          value-format="YYYY-MM-DD HH:mm:ss"
      />
    </el-form-item>
   
    <el-form-item label="订单状态：" prop="name">
      <el-select v-model="ruleForm.queryRo.status" clearable style="width: 150px">
        <el-option
                    v-for="item in orderStatusList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                />
      </el-select>
    </el-form-item>
    <el-form-item label="订单类型：" prop="chargeTimeTypeList">
      <el-select v-model="ruleForm.queryRo.chargeTimeType" clearable style="width: 150px">
        <el-option
                    v-for="item in chargeTimeTypeList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                />
      </el-select>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="search">查 询</el-button>
    </el-form-item>
  </el-form>

  <el-table :data="tableList" style="width: 100%" v-loading="loading">
    <el-table-column prop="orderNo" label="订单编号" align="center" width="300px" />
    <el-table-column prop="chargeTimeType" label="订单类型" align="center">
      <template #default="scope">
        <span >{{ chargeTimeTypeNum(scope.row.chargeTimeType) }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="userName" label="用户昵称" align="center" width="100px" />
    <el-table-column prop="vehicleNo" label="用户车牌" align="center" width="100px" />
    <el-table-column prop="createTime" label="下单时间" align="center" />
    <el-table-column prop="preordeBeginTime" label="预约时间" align="center" width="100px" />

<!--    <el-table-column prop="chargeBeginTime" label="充电开始时间" align="center" />-->
    <el-table-column prop="chargeEndTime" label="充电完成时间" align="center" />
    <el-table-column prop="payTime" label="订单完成时间" align="center" />
    <el-table-column prop="cancelTime" label="取消时间" align="center" />
    <el-table-column prop="" label="取消原因" align="center" width="200px" >
      <template #default="scope">
        <span>{{ ((scope.row.workerCancelReason || '') + (scope.row.userCancelReason || ''))  || '无'}}</span><br>
        详情:<br>
        <span>{{ ((scope.row.workerCancelReasonDetail) || '') + ((scope.row.userCancelReasonDetail) || '') || '无' }}</span><br>
      </template>
    </el-table-column>
    <el-table-column prop="address" label="订单地址"  align="center" />
    <el-table-column prop="" label="下单度数" align="center" />
    <el-table-column prop="powerCharge" label="实际充电度数" align="center" />
    <el-table-column prop="price" label="订单金额" align="center">
      <template #default="scope">
        <span >{{ scope.row.endMoney+'元' }}</span>
      </template>
    </el-table-column>
    <el-table-column prop="feeType" label="支付方式" align="center">
      <template #default="scope">
        <span >{{ scope.row.feeType||'-'}}</span>
      </template>
    </el-table-column>
    <el-table-column prop="payMoney" label="实际支付金额" align="center" />
    <el-table-column prop="status" label="订单状态" align="center">
      <template #default="scope">
        <span >{{ statusCn(scope.row.status) }}</span>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center">
      <template #default="scope">
        <el-button link @click="openDialog(scope.row)" type="primary">查看详情</el-button>
      </template>
    </el-table-column>
  </el-table>

  <footer class="pagination">
    <el-pagination
      v-model:currentPage="ruleForm.current"
      v-model:page-size="ruleForm.pageSize"
      :page-sizes="[10, 20, 30, 50]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      small
    />
  </footer>

  <OrderDetailDialog
      v-model:show="showDialog"
      :detail="detail"
      @openDialog="openDialog"
  ></OrderDetailDialog>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from 'vue'
import OrderDetailDialog from './components/OrderDetailDialog.vue'
import api from '@/api/apis/orderApi'
import {ElMessage} from "element-plus";
const ruleForm = reactive({
  queryRo:{
    orderNo:"",
    chargeBeginTime:"",
    chargeEndTime:"",
    chargeTimeType:"",
    createTime:"",
    status:undefined
  },
  current: 1,
  pageSize: 50,
  searchCount: true
})
const time=ref<any>([])
const createtime=ref<any>('')


//总数
const total = ref(0)
//搜索
const search = () => {
  ruleForm.current = 1
  getTableList()
}

const statusCn = (value: string) => {
  let obj: any = {
    0: '提交订单',
    1: '司机接单',
    2: '充电中',
    // 3: '充电暂停',
    4: '未支付',
    5: '已支付',
    6: '预约订单',
    7: '司机已抢单',
    8: '司机已取消',
    9: '用户已取消',
  }
  return obj[value]
}

const chargeTimeTypeNum = (value: string) => {
  let obj: any = {
    '00': '即刻—标准充电',
    '01': '预约—标准充电',
    '02': '即刻—定制充电',
    '03': '预约—定制充电',
  }
  return obj[value]
}
const orderStatusList=[
  {name:"提交订单",value:0},
  {name:"司机接单",value:1},
  {name:"充电中",value:2},
  // {name:"充电暂停",value:3},
  {name:"未支付",value:4},
  {name:"已支付",value:5},
  {name:"预约订单",value:6},
  {name:"司机已抢单",value:7},
  {name:"司机已取消",value:8},
  {name:"用户已取消",value:9},
]
const chargeTimeTypeList=[
  {name:"即刻—标准充电",value:"00"},
  {name:"预约—标准充电",value:"01"},
  {name:"即刻—定制充电",value:"02"},
  {name:"预约—定制充电",value:"03"},

]

//表格数据
const tableList = ref([])
//加载
const loading = ref(false)
onMounted(()=>{
  getTableList()
})
//获取表格数据
const getTableList = async () => {
  loading.value = true
  try {
    let obj = { ...ruleForm }
    obj.queryRo.chargeBeginTime =time.value?time.value[0]:undefined
    obj.queryRo.chargeEndTime =time.value?time.value[1]:undefined
    obj.queryRo.createTime =createtime.value?createtime.value:undefined
    let {data} = await api.chargeOrderPage(obj)
    tableList.value= data.data.rows
    total.value= Number(data.data.total)

  } catch (error) {
    loading.value = false
  }
  loading.value = false
}
// //改变每页条数
const handleSizeChange = (val: number) => {
  ruleForm.current = 1
  ruleForm.pageSize = val
  getTableList()
}
//改变当前页数
const handleCurrentChange = (val: number) => {
  ruleForm.current = val
  getTableList()
}

//弹框开关
const showDialog = ref(false)
//详情id
const detail = ref()
//打开详情弹框
const openDialog = (val: string) => {
  detail.value = val
  console.log('值---',val)
  showDialog.value = true
}

//根据id查询司机信息
// const openDialog = async(id:string) => {
//   let { data } = await api.getDriver({ id })
// }

</script>

<style scoped lang="scss">
footer {
  display: flex;
  justify-content: center;
  margin-top: 15px;
}
</style>
